package cytj.setup.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import cytj.setup.R;
import cytj.setup.bean.Data;

/**
 * 蓝牙接收数据的DataListView的Adapter
 * Created by LTP on 2015/12/28
 */
public class DataReceiveAdapter extends ArrayAdapter<Data> {
    private int itemResource;

    public DataReceiveAdapter(Context context, int resource, List<Data> objects) {
        super(context, resource, objects);
        itemResource = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Data data = getItem(position);
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(itemResource, null, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.time.setText(data.getTime());
        viewHolder.dataContent.setText(data.getDataContent());
        return convertView;
    }

    class ViewHolder {
        private TextView time;
        private TextView dataContent;

        private ViewHolder(View view) {
            time = (TextView) view.findViewById(R.id.textView_time_dataReceiveList);
            dataContent = (TextView) view.findViewById(R.id.textView_dataContent_dataReceiveList);
        }
    }
}
